/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.university.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.university.entity.XueLiLevel;
import com.thinkgem.jeesite.modules.university.service.XueLiLevelService;

/**
 * 学历层次Controller
 * @author 朱俊吉
 * @version 2017-12-08
 */
@Controller
@RequestMapping(value = "${adminPath}/university/xueLiLevel")
public class XueLiLevelController extends BaseController {

	@Autowired
	private XueLiLevelService xueLiLevelService;
	
	@ModelAttribute
	public XueLiLevel get(@RequestParam(required=false) String id) {
		XueLiLevel entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = xueLiLevelService.get(id);
		}
		if (entity == null){
			entity = new XueLiLevel();
		}
		return entity;
	}
	
	@RequiresPermissions("university:xueLiLevel:view")
	@RequestMapping(value = {"list", ""})
	public String list(XueLiLevel xueLiLevel, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<XueLiLevel> page = xueLiLevelService.findPage(new Page<XueLiLevel>(request, response), xueLiLevel); 
		model.addAttribute("page", page);
		return "modules/university/xueLiLevelList";
	}

	@RequiresPermissions("university:xueLiLevel:view")
	@RequestMapping(value = "form")
	public String form(XueLiLevel xueLiLevel, Model model) {
		model.addAttribute("xueLiLevel", xueLiLevel);
		return "modules/university/xueLiLevelForm";
	}

	@RequiresPermissions("university:xueLiLevel:edit")
	@RequestMapping(value = "save")
	public String save(XueLiLevel xueLiLevel, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, xueLiLevel)){
			return form(xueLiLevel, model);
		}
		xueLiLevelService.save(xueLiLevel);
		addMessage(redirectAttributes, "保存学历层次成功");
		return "redirect:"+Global.getAdminPath()+"/university/xueLiLevel/?repage";
	}
	
	@RequiresPermissions("university:xueLiLevel:edit")
	@RequestMapping(value = "delete")
	public String delete(XueLiLevel xueLiLevel, RedirectAttributes redirectAttributes) {
		xueLiLevelService.delete(xueLiLevel);
		addMessage(redirectAttributes, "删除学历层次成功");
		return "redirect:"+Global.getAdminPath()+"/university/xueLiLevel/?repage";
	}

}